import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 将屏幕划分为10份
import 'amfe-flexible'

// 引入Vant组件
import { NavBar, Form, Field, Button, Tabbar, TabbarItem, Icon, Tab, Tabs, Cell, CellGroup, List, PullRefresh, ActionSheet, Dialog, Popup, Badge, Col, Row, Search, Divider, Tag, Image as VanImage, DatetimePicker } from 'vant'

// 导入全局组件 ArticleItem 并全局注册
import ArticleItem from './components/ArticleItem.vue'

// 时间
import { formatTimeAgoFn } from './utils/date'

import './permission'
Vue.component(ArticleItem.name, ArticleItem)

// 把公共函数 加入 到 vue 的原型上
Vue.prototype.formatTimeAgoFn = formatTimeAgoFn

Vue.use(NavBar)
Vue.use(Form)
Vue.use(Field)
Vue.use(Button)
Vue.use(Tabbar)
Vue.use(TabbarItem)
Vue.use(Icon)
Vue.use(Tab)
Vue.use(Tabs)
Vue.use(Cell)
Vue.use(CellGroup)
Vue.use(List)
Vue.use(PullRefresh)
Vue.use(ActionSheet)
Vue.use(Dialog)
Vue.use(Popup)
Vue.use(Badge)
Vue.use(Col)
Vue.use(Row)
Vue.use(Search)
Vue.use(Divider)
Vue.use(Tag)
Vue.use(VanImage)
Vue.use(DatetimePicker)

Vue.config.productionTip = false

// 给二级反馈 注册聚焦事件
Vue.directive('foc', {
  // 当指令所在元素插入到dom中自动触发
  inserted (el) {
    // console.log(el.tagName) // DIV
    // console.log(el.nodeName) // DIV
    if (['INPUT', 'TEXTAREA'].indexOf(el.tagName) !== -1) {
      el.focus()
    } else {
      let node = el.querySelector('input')
      if (node) {
        node.focus()
        return
      }
      node = el.querySelector('textarea')
      if (node) {
        node.focus()
        return
      }
      throw new Error('请把foc指令用在input或textarea上')
    }
    // el.children[0].children[0].children[0].focus()
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
